import FUtil from "./../io/io";
import Render from "./../render/render";
import nunjucks from './../render/view'
var path = require('path')

function fout(basePath, content, outPath) { 
    FUtil.out(content, path.resolve(basePath.out, outPath));
}

async function gtem(temPath, basePath) {
    return FUtil.open(path.resolve(basePath.tem, temPath));
}

export default async function generator(data, tem, outpath, baseConfig) {   
    let temstr = await gtem(tem, baseConfig);
    //console.log(temstr);    
    //let rsStr = Render.render(data, temstr);
    let rsStr = nunjucks.render(path.resolve(baseConfig.tem, tem), data);
    fout(baseConfig, rsStr, outpath);
    return "ok";
}